package org.thread.test00.demo05.t02;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author ZQX
 * @date 2025-03-12
 */
public class MainTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 第二：创建实现Callable接口的对象
        MyCallable mc01 = new MyCallable(1, 100);
        MyCallable mc02 = new MyCallable(101, 800);
        MyCallable mc03 = new MyCallable(801, 1000);

        // 第三：创建 FutureTask 对象
        FutureTask<Integer> task01 = new FutureTask<>(mc01);
        FutureTask<Integer> task02 = new FutureTask<>(mc02);
        FutureTask<Integer> task03 = new FutureTask<>(mc03);

        // 第四：创建线程对象
        Thread t01 = new Thread(task01);
        Thread t02 = new Thread(task02);
        Thread t03 = new Thread(task03);

        // 第五：启动线程
        t01.start();
        t02.start();
        t03.start();

        int s = task01.get() + task02.get() + task03.get();
        System.out.println("和为：" + s);
    }
}
